'use strict';
dataloaderApp.controller ('ProxyCtrl' , [ '$scope', '$rootScope', '$route','$routeParams' , '$location',  '$filter' , 'proxyService'
		, function ( $scope, $rootScope, $route, $routeParams , $location,  $filter , proxyService) {

	$scope.proxy = {};
	
	$scope.$on ('exception', function(event,args) {
		$scope.exceptionInfo = { message : args.localMessage };
		$scope.hasError = true;
		setTimeout(function () {   
   			$scope.hasError = false;
   			$scope.$apply();
		},10000);
	});	

	$scope.$on('success', function (event,args) {
		$scope.hasSuccess = true;
		setTimeout(function () {   
   			$scope.hasSuccess = false;
   			$scope.$apply();
		},10000);

	});
	
	$scope.get = function () {
		proxyService.get ().then(function (response) {
			$scope.proxy = response;
		});
	};

	$scope.setUp = function () {
		if (!$scope.proxy) return;

		proxyService.save ($scope.proxy).then(function(respone) {
			
			$rootScope.$broadcast('success', {	message : 'Usuario Adicionado com sucesso'	});
		});
	};
 	
			
}]);
